package com.km.controller;

import com.km.entity.DingdingTokenEntity;
import com.km.service.DingdingTokenService;
import com.km.utils.PageUtils;
import com.km.utils.Query;
import com.km.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-06-19 17:17:39
 */
@RestController
@RequestMapping("dingdingtoken")
public class DingdingTokenController {
    @Autowired
    private DingdingTokenService dingdingTokenService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dingdingtoken:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DingdingTokenEntity> dingdingTokenList = dingdingTokenService.queryList(query);
        int total = dingdingTokenService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(dingdingTokenList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dingdingtoken:info")
    public R info(@PathVariable("id") Long id) {
        DingdingTokenEntity dingdingToken = dingdingTokenService.queryObject(id);

        return R.ok().put("dingdingToken", dingdingToken);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dingdingtoken:save")
    public R save(@RequestBody DingdingTokenEntity dingdingToken) {
        dingdingTokenService.save(dingdingToken);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dingdingtoken:update")
    public R update(@RequestBody DingdingTokenEntity dingdingToken) {
        dingdingTokenService.update(dingdingToken);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dingdingtoken:delete")
    public R delete(@RequestBody Long[] ids) {
        dingdingTokenService.deleteBatch(ids);

        return R.ok();
    }

}
